<template>
  <div>
    <!--以下是审批字段-->
    <div>
      <el-form label-width="100px">
        <el-divider></el-divider>
        <el-form-item :label="taskName === '调整申请' ? '调整申请' : '办理' ">
          <el-radio-group v-model="pass">
            <el-radio label="true">{{ taskName === '调整申请' ? '确定调整' : '同意' }}</el-radio>
            <el-radio label="false">{{ taskName === '调整申请' ? '直接撤回' : '退回' }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="批注" prop="remark">
          <el-input v-model="comment" type="textarea" :value="comment"/>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="view-footer">
      <el-button v-show="type === 'todo'" type="primary" @click="complete" style="margin-right: 30px">确 定</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'
import Bus from '@/utils/bus.js'

export default {
  name: 'ViewVerify',
  props: {
    row: {
      type: Object
    },
    showAdd: {
      type: Object
    },
    taskId: {
      type: String
    },
    //2022年6月6日 LQ
    taskName: {
      type: String
    },
    taskDefKey: {
      type: String
    },
    type: {
      type: String
    }
  },
  data() {
    return {
      pass: 'true',
      comment: '同意'
    }
  },
  mounted() {
    this.changeComment()
  },
  computed: {
    // comment:{
    //   get(){
    //     if (this.taskName === '调整申请') {
    //       return '同意调整'
    //     } else {
    //       return '同意'
    //     }
    //   },
    //     set(v){
    //
    //     }
    //
    // }

  },
  methods: {
    close: function() {
      this.showAdd.showcp = false
      //this.$emit('update:open', false)
    },
    changeComment() {

      if (this.taskName === '调整申请') {
        this.comment = '确定调整'
      } else {
        this.comment = '同意'
      }
    },
    complete() {
      let that = this
      const data = {
        'taskId': this.taskId,
        'instanceId': this.row.instanceId,
        'variables': JSON.stringify({
          'comment': this.comment,
          'pass': this.pass,
          // 'formData': this.row//有问题，传整个formData，报错，说请求头太大
          //
          'applyUserId': this.row.applyUserId
        })
      }
      if (this.taskName === '调整申请') {//这里要先保存一下。
        this.$confirm('是否提交？ 修改项目信息后必须先点击“保存”！！！，确定修改成功后在提交申请，不然会原封不动直接提交给上级审核部门', '警告', {
          confirmButtonText: '确定提交',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          Bus.$emit('createGBZCBProjectreReapplySubmit')
          request({
            url: '/activiti/process/complete',
            method: 'post',
            params: data
          }).then(response => {
            that.msgSuccess('操作成功')
            that.close()
          })
        })
      } else {
        this.$confirm('是否确定？ 点击确定后表示本环节审批流完成！', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          request({
            url: '/activiti/process/complete',
            method: 'post',
            params: data
          }).then(response => {
            that.msgSuccess('操作成功')
           Bus.$emit("getWorkflowTodoList");
            that.close()
            // 刷新待办事项列表（丑陋的代码 👇）
            // 2022年5月31日 LQ 修改下
            // this.$parent.$parent.$parent.$parent.$parent.$parent.getList();
            //  Bus.$emit('getWorkflowTodoList')
          })
        })
      }

      //   this.$parent.$children[0].validate(valid => {
      //     if (valid) {
      //   }
      // })

    }
  },
  watch: {
    pass: function(val) {
      let currentCom = null
      if (val === 'true') {
        if (this.taskName === '调整申请') {
          currentCom = '确定调整'
        } else {
          currentCom = '同意'
        }
      } else {
        if (this.taskName === '调整申请') {
          currentCom = '不调整，直接撤回，重新申请'
        } else {
          currentCom = '退回'
        }
      }
      this.comment = currentCom
    }
  }
}

</script>

<style scoped>
.view-footer {
  text-align: center;
  margin-left: 100px;
}
</style>
